<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - png_loader.cpp</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2008  Davis E. King (davis@dlib.net), Nils Labugt
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_PNG_LOADER_CPp_
<font color='#0000FF'>#define</font> DLIB_PNG_LOADER_CPp_

<font color='#009900'>// only do anything with this file if DLIB_PNG_SUPPORT is defined
</font><font color='#0000FF'>#ifdef</font> DLIB_PNG_SUPPORT

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../array2d.h.html'>../array2d.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../pixel.h.html'>../pixel.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../dir_nav.h.html'>../dir_nav.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='png_loader.h.html'>png_loader.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>png.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../string.h.html'>../string.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../byte_orderer.h.html'>../byte_orderer.h</a>"

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>struct</font> <b><a name='LibpngData'></a>LibpngData</b>
    <b>{</b>
        png_bytep<font color='#5555FF'>*</font> row_pointers_;
        png_structp png_ptr_;
        png_infop info_ptr_;
        png_infop end_info_;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    png_loader::
    <b><a name='png_loader'></a>png_loader</b><font face='Lucida Console'>(</font> <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> filename <font face='Lucida Console'>)</font> : height_<font face='Lucida Console'>(</font> <font color='#979000'>0</font> <font face='Lucida Console'>)</font>, width_<font face='Lucida Console'>(</font> <font color='#979000'>0</font> <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>read_image</font><font face='Lucida Console'>(</font> filename <font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    png_loader::
    <b><a name='png_loader'></a>png_loader</b><font face='Lucida Console'>(</font> <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> filename <font face='Lucida Console'>)</font> : height_<font face='Lucida Console'>(</font> <font color='#979000'>0</font> <font face='Lucida Console'>)</font>, width_<font face='Lucida Console'>(</font> <font color='#979000'>0</font> <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>read_image</font><font face='Lucida Console'>(</font> filename.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    png_loader::
    <b><a name='png_loader'></a>png_loader</b><font face='Lucida Console'>(</font> <font color='#0000FF'>const</font> dlib::file<font color='#5555FF'>&amp;</font> f <font face='Lucida Console'>)</font> : height_<font face='Lucida Console'>(</font> <font color='#979000'>0</font> <font face='Lucida Console'>)</font>, width_<font face='Lucida Console'>(</font> <font color='#979000'>0</font> <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>read_image</font><font face='Lucida Console'>(</font> f.<font color='#BB00BB'>full_name</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> png_loader::<b><a name='get_row'></a>get_row</b><font face='Lucida Console'>(</font> <font color='#0000FF'><u>unsigned</u></font> i <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_pointers_[i];
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    png_loader::~<b><a name='png_loader'></a>png_loader</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font> ld_ <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_pointers_ <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL <font face='Lucida Console'>)</font>
            <font color='#BB00BB'>png_destroy_read_struct</font><font face='Lucida Console'>(</font> <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_ <font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>end_info_ <font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> png_loader::<b><a name='is_gray'></a>is_gray</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font face='Lucida Console'>(</font> color_type_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_COLOR_TYPE_GRAY <font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> png_loader::<b><a name='is_graya'></a>is_graya</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font face='Lucida Console'>(</font> color_type_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_COLOR_TYPE_GRAY_ALPHA <font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> png_loader::<b><a name='is_rgb'></a>is_rgb</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font face='Lucida Console'>(</font> color_type_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_COLOR_TYPE_RGB <font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> png_loader::<b><a name='is_rgba'></a>is_rgba</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font face='Lucida Console'>(</font> color_type_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_COLOR_TYPE_RGB_ALPHA <font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#009900'>// Don't do anything when libpng calls us to tell us about an error.  Just return to 
</font>    <font color='#009900'>// our own code and throw an exception (at the long jump target).
</font>    <font color='#0000FF'><u>void</u></font> <b><a name='png_loader_user_error_fn_silent'></a>png_loader_user_error_fn_silent</b><font face='Lucida Console'>(</font>png_structp  png_struct, png_const_charp <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#BB00BB'>longjmp</font><font face='Lucida Console'>(</font><font color='#BB00BB'>png_jmpbuf</font><font face='Lucida Console'>(</font>png_struct<font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
    <b>}</b>
    <font color='#0000FF'><u>void</u></font> <b><a name='png_loader_user_warning_fn_silent'></a>png_loader_user_warning_fn_silent</b><font face='Lucida Console'>(</font>png_structp , png_const_charp <font face='Lucida Console'>)</font> 
    <b>{</b>
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> png_loader::<b><a name='read_image'></a>read_image</b><font face='Lucida Console'>(</font> <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> filename <font face='Lucida Console'>)</font>
    <b>{</b>
        ld_.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> LibpngData<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font> filename <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>image_load_error</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>png_loader: invalid filename, it is NULL</font>"<font face='Lucida Console'>)</font>;
        <b>}</b>
        FILE <font color='#5555FF'>*</font>fp <font color='#5555FF'>=</font> <font color='#BB00BB'>fopen</font><font face='Lucida Console'>(</font> filename, "<font color='#CC0000'>rb</font>" <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font> <font color='#5555FF'>!</font>fp <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>image_load_error</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>png_loader: unable to open file </font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> filename<font face='Lucida Console'>)</font>;
        <b>}</b>
        png_byte sig[<font color='#979000'>8</font>];
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>fread</font><font face='Lucida Console'>(</font> sig, <font color='#979000'>1</font>, <font color='#979000'>8</font>, fp <font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>8</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font> fp <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>image_load_error</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>png_loader: error reading file </font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> filename<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font> <font color='#BB00BB'>png_sig_cmp</font><font face='Lucida Console'>(</font> sig, <font color='#979000'>0</font>, <font color='#979000'>8</font> <font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font> fp <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>image_load_error</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>png_loader: format error in file </font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> filename<font face='Lucida Console'>)</font>;
        <b>}</b>
        ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_ <font color='#5555FF'>=</font> <font color='#BB00BB'>png_create_read_struct</font><font face='Lucida Console'>(</font> PNG_LIBPNG_VER_STRING, NULL, <font color='#5555FF'>&amp;</font>png_loader_user_error_fn_silent, <font color='#5555FF'>&amp;</font>png_loader_user_warning_fn_silent <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font> fp <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>image_load_error</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>png_loader: parse error in file </font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> filename<font face='Lucida Console'>)</font>;
        <b>}</b>
        ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font color='#5555FF'>=</font> <font color='#BB00BB'>png_create_info_struct</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_ <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font> fp <font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>png_destroy_read_struct</font><font face='Lucida Console'>(</font> <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_ <font face='Lucida Console'>)</font>, <font face='Lucida Console'>(</font> png_infopp <font face='Lucida Console'>)</font>NULL, <font face='Lucida Console'>(</font> png_infopp <font face='Lucida Console'>)</font>NULL <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>image_load_error</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>png_loader: parse error in file </font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> filename<font face='Lucida Console'>)</font>;
        <b>}</b>
        ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>end_info_ <font color='#5555FF'>=</font> <font color='#BB00BB'>png_create_info_struct</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_ <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>end_info_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font> fp <font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>png_destroy_read_struct</font><font face='Lucida Console'>(</font> <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_ <font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font face='Lucida Console'>)</font>, <font face='Lucida Console'>(</font> png_infopp <font face='Lucida Console'>)</font>NULL <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>image_load_error</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>png_loader: parse error in file </font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> filename<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>setjmp</font><font face='Lucida Console'>(</font><font color='#BB00BB'>png_jmpbuf</font><font face='Lucida Console'>(</font>ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// If we get here, we had a problem writing the file 
</font>            <font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font>fp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>png_destroy_read_struct</font><font face='Lucida Console'>(</font> <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_ <font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>end_info_ <font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>image_load_error</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>png_loader: parse error in file </font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> filename<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#BB00BB'>png_set_palette_to_rgb</font><font face='Lucida Console'>(</font>ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_<font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>png_init_io</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_, fp <font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>png_set_sig_bytes</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_, <font color='#979000'>8</font> <font face='Lucida Console'>)</font>;
        <font color='#009900'>// flags force one byte per channel output
</font>        byte_orderer bo;
        <font color='#0000FF'><u>int</u></font> png_transforms <font color='#5555FF'>=</font> PNG_TRANSFORM_PACKING;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>bo.<font color='#BB00BB'>host_is_little_endian</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            png_transforms <font color='#5555FF'>|</font><font color='#5555FF'>=</font> PNG_TRANSFORM_SWAP_ENDIAN;
        <font color='#BB00BB'>png_read_png</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_, ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_, png_transforms, NULL <font face='Lucida Console'>)</font>;
        height_ <font color='#5555FF'>=</font> <font color='#BB00BB'>png_get_image_height</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_, ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font face='Lucida Console'>)</font>;
        width_ <font color='#5555FF'>=</font> <font color='#BB00BB'>png_get_image_width</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_, ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font face='Lucida Console'>)</font>;
        bit_depth_ <font color='#5555FF'>=</font> <font color='#BB00BB'>png_get_bit_depth</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_, ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font face='Lucida Console'>)</font>;
        color_type_ <font color='#5555FF'>=</font> <font color='#BB00BB'>png_get_color_type</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_, ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font> info_ptr_ <font face='Lucida Console'>)</font>;


        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>color_type_ <font color='#5555FF'>!</font><font color='#5555FF'>=</font> PNG_COLOR_TYPE_GRAY <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
            color_type_ <font color='#5555FF'>!</font><font color='#5555FF'>=</font> PNG_COLOR_TYPE_RGB <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
            color_type_ <font color='#5555FF'>!</font><font color='#5555FF'>=</font> PNG_COLOR_TYPE_RGB_ALPHA <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
            color_type_ <font color='#5555FF'>!</font><font color='#5555FF'>=</font> PNG_COLOR_TYPE_GRAY_ALPHA<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font> fp <font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>png_destroy_read_struct</font><font face='Lucida Console'>(</font> <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_ <font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>end_info_ <font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>image_load_error</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>png_loader: unsupported color type in file </font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> filename<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>bit_depth_ <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>8</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> bit_depth_ <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>16</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font> fp <font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>png_destroy_read_struct</font><font face='Lucida Console'>(</font> <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_ <font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>end_info_ <font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>image_load_error</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>png_loader: unsupported bit depth of </font>" <font color='#5555FF'>+</font> <font color='#BB00BB'>cast_to_string</font><font face='Lucida Console'>(</font>bit_depth_<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> "<font color='#CC0000'> in file </font>" <font color='#5555FF'>+</font> std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>filename<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_pointers_ <font color='#5555FF'>=</font> <font color='#BB00BB'>png_get_rows</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_, ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font> fp <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_pointers_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>png_destroy_read_struct</font><font face='Lucida Console'>(</font> <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr_ <font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr_ <font face='Lucida Console'>)</font>, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font> ld_<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>end_info_ <font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>throw</font> <font color='#BB00BB'>image_load_error</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>png_loader: parse error in file </font>"<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> filename<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_PNG_SUPPORT
</font>
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_PNG_LOADER_CPp_
</font>

</pre></body></html>